package sample.tangocho.dataaccess;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

public class TangochoSQLiteOpenHelper extends SQLiteOpenHelper {
	
	private static TangochoSQLiteOpenHelper tangochoSQLiteOpenHelper;

	/** データベースファイル名 */
	private static final String DB_NAME = "tangocho.db";
	
	/** データベースバージョン */
	private static final int DATABASE_VERSION = 1;
	private static final String TANGOCHO_TABLE_NAME = "tangocho";
	private static final String CARD_TABLE_NAME = "card";
	private static final String TANGOCHO_TABLE_CREATE = "CREATE TABLE " + TANGOCHO_TABLE_NAME + " (_id integer primary key autoincrement, title text, last_updated integer)";
	private static final String CARD_TABLE_CREATE = "CREATE TABLE " + CARD_TABLE_NAME + " (_id integer primary key autoincrement, tangocho_id integer, front_text text, back_text text, last_updated integer)"; 

	private TangochoSQLiteOpenHelper(Context context) {
		super(context, DB_NAME, null, DATABASE_VERSION);
	}
	
	public static TangochoSQLiteOpenHelper getInstance(Context context) {
		if (tangochoSQLiteOpenHelper == null) {
			tangochoSQLiteOpenHelper = new TangochoSQLiteOpenHelper(context);
		}
		return tangochoSQLiteOpenHelper;
	}

	/**
	 * データベース新規作成時、テーブルを作成。
	 */
	@Override
	public void onCreate(SQLiteDatabase db) {
		db.execSQL(TANGOCHO_TABLE_CREATE);
		db.execSQL(CARD_TABLE_CREATE);
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub

	}

}
